const Koa = require('koa');
const path = require('path');
const app = new Koa();
const cors= require('koa2-cors');
const { koaBody } = require('koa-body');
const statics = require('koa-static');
const router = require('koa-router')();
app.use(cors());
app.use(statics(path.resolve('./examples')));
app.use(statics(path.resolve('./lib')));
app.use(
	koaBody({
		multipart: true,
		formidable: {
			multipart: true,
			maxFileSize: 10 * 1024 * 1024,
		},
	})
);

router.get('/report', async ctx => {
	console.log(JSON.stringify(ctx.query));
	return (ctx.body = {
		code: 0,
		message: '成功',
		data: {},
	});
});

router.post('/report', async ctx => {
	console.log(ctx.request.body);
	return (ctx.body = {
		code: 0,
		message: '成功',
		data: {},
	});
});

router.post('/user', async ctx => {
	return (ctx.body = {
		code: 0,
		message: '成功',
		data: {},
	});
});

router.get('/user111', async ctx => {
	return (ctx.body = {
		code: 0,
		message: '成功',
		data: {},
	});
});



app.use(router.routes());
app.use(router.allowedMethods());

app.listen(9001, () => {
	console.log('服务已启动端口:9001');
});
